package com.tool_stdy.ConcurrencyModel.ProductConsumer;

import com.tool_stdy.ConcurrencyModel.WorkMastser.Task;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by yan_li on 2016/11/11.
 */
public class PCClient {
    public static void main(String[] args) throws InterruptedException {
        Queue<Task> workQueue = new ConcurrentLinkedQueue<Task>();
        ExecutorService executor = Executors.newFixedThreadPool(3);
        CountDownLatch latch = new CountDownLatch(5000);
        Consumer cum = new Consumer(workQueue,latch);
        Product pro = new Product(workQueue);
        long start  =System.currentTimeMillis();
        for (int i = 0; i < 5000; i++) {
            Task t = new Task();
            t.setPrice(i);
            pro.addTask(t);
        }
        for(int i=0;i<3;i++){
            executor.submit(cum);
        }
        latch.await();
        System.out.println("userd:"+(System.currentTimeMillis()-start));
        Thread.sleep(100000);
    }
}
